package com.meituan.service.impl;

import com.meituan.mapper.EvaluateMapper;
import com.meituan.mapper.OrderMapper;
import com.meituan.model.EvaluateEntity;
import com.meituan.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EvaluateServiceImpl implements EvaluateService {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    EvaluateMapper evaluateMapper;

    @Override
    public List<EvaluateEntity> findByShopId(String shopId) {
        return evaluateMapper.findByShopId(shopId);
    }

    @Override
    public Integer add(EvaluateEntity evaluateEntity) {
        String shopId = orderMapper.findShopId(String.valueOf(evaluateEntity.getOrderId()));
        if(shopId!=null){
            evaluateEntity.setShopId(Integer.parseInt(shopId));
            if(evaluateMapper.insert(evaluateEntity)==1){
                return orderMapper.updateIsEvaluate(String.valueOf(evaluateEntity.getOrderId()));
            }
        }
        return 0;
    }
}
